package com.kbtd.config;

import com.kbtd.interceptor.LoginInterceptor;
import com.kbtd.interceptor.TokenFlushInterceptor;
import com.kbtd.interceptor.UVInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import javax.annotation.Resource;

/**
 * WebMvc配置类
 *
 * @author wp
 * @version 1.0
 */
@Slf4j
@Configuration
public class WebConfiguration extends WebMvcConfigurationSupport {

    @Value("${login.http.exclude:null}")
    private String[] excludeHttps;

    @Resource
    private LoginInterceptor loginInterceptor;
    @Resource
    private TokenFlushInterceptor tokenFlushInterceptor;
    @Resource
    private UVInterceptor uvInterceptor;
    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)
                .excludePathPatterns(excludeHttps).order(3);

        registry.addInterceptor(tokenFlushInterceptor)
                .addPathPatterns("/**").order(2);

        registry.addInterceptor(tokenFlushInterceptor)
                .addPathPatterns("/**").order(1);
    }
}
